@extends('layouts.app')

@section('content')
<!-- Main content -->
<section class="content">
  <div class="row">
    <div class="col-xs-12">
      @include('layouts.utils.success')
      <div class="box">
        <div class="box-header">
          <a href="{{ url('/api_admin/role') }}" class="btn btn-default">返回</a>
        </div>
        <div class="box-body table-responsive no-padding">
			    <form class="form-horizontal col-md-6 col-md-offset-3" action="{{ url('/api_admin/role/'.$role->id) }}" method="post">
            {!! csrf_field() !!}
            {{ method_field('PUT') }}
            <div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
              <label for="name" class="col-sm-2 control-label">角色名<small>name</small></label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="name" value="{{ $role->name }}" name="name">
                @if ($errors->has('name'))
                  <span class="help-block">
                    <strong>{{ $errors->first('name') }}</strong>
                  </span>
                @endif
              </div>
            </div>
            <div class="form-group {{ $errors->has('display_name') ? ' has-error' : '' }}">
              <label for="display_name" class="col-sm-2 control-label">角色名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="display_name" value="{{ $role->display_name }}" name="display_name">
                @if ($errors->has('display_name'))
                  <span class="help-block">
                    <strong>{{ $errors->first('display_name') }}</strong>
                  </span>
                @endif
              </div>
            </div>
            <div class="form-group {{ $errors->has('description') ? ' has-error' : '' }}">
              <label for="description" class="col-sm-2 control-label">角色描述</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="description" value="{{ $role->description}}" name="description">
                @if ($errors->has('description'))
                  <span class="help-block">
                    <strong>{{ $errors->first('description') }}</strong>
                  </span>
                @endif
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">增加权限</label>
              @forelse($permissions as $permission)
                <label class="col-sm-2 control-label"></label>
                <div class="checkbox col-sm-10">
                  <label>
                    <input type="checkbox" value="{{ $permission->id }}" name="permissions[]" 
                    @if(in_array($permission->id, $perms))
                    checked 
                    @endif>
                    {{ $permission->display_name }}
                  </label>
                </div>
              @empty
                <div class="checkbox col-sm-10">无权限</div>
              @endforelse
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">修改</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>
@endsection